using System;
using System.Collections.Generic;
using System.Text;
using SQLServices.Runners;
using SQLServices.Runners.Events;

namespace SQLRunnerLib.TransMgr
{
    class RollbackTransactionConnMgr:CommitTransactionConnMgr
    {
        public RollbackTransactionConnMgr(IRunner runner) : base(runner)
        {
        }

        /// <summary>
        /// When the Runner has finished the execution of all scripts it calls this method.
        /// Each Transaction manager must implement this method.
        /// </summary>
        protected override void OnExecutionFinished(object sender, ExecutionFinishedEventArgs e)
        {
            if (_isInTransaction)
            {
                if (_mainConn.GetTranCount() != 0)
                    _mainConn.Execute("Rollback");
                CleanConnection(ref _mainConn);
                CleanConnection(ref _monitorConn);
                _isInTransaction = false;
            }
        }
    }
}
